package com.xm.servlet.reception_desk.login;

import com.xm.service.reception_desk.AccountService;
import lombok.SneakyThrows;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author 康文程
 * @date 2023-12-13 下午 02:04
 */
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    private final AccountService service = new AccountService();
    /**
     *登陆页面
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        Integer menu = req.getParameter("menu") == null ? 0 : Integer.parseInt(req.getParameter("menu"));
        System.out.println(menu);
        req.setAttribute("menu",menu);
        req.getRequestDispatcher("/WEB-INF/page/reception_desk/login.jsp").forward(req, resp);
    }

    /**
     * 邮箱注册
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
        String mailbox = req.getParameter("mailbox");
        boolean isPhoneExist = service.checkMailboxExist(mailbox);
        resp.getWriter().println(isPhoneExist);
    }
}
